<template>
	<view class="goods-list">
		<view class="goods-item" v-for="(item, index) in goodsList" :key="index" @tap="toDetail(item.id)">
			<view class="goods-item-img">
				<image :src="item.thumb" class="img" mode="aspectFill"></image>
			</view>

			<view class="goods-item-content">
				<view class="title">{{ item.name }}</view>
				<view class="bottom">
					<view class="price">
						<text class="sale-price">￥{{ item.money }}</text>
						<text class="factory-price">￥{{ item.factoryPrice }}</text>
					</view>
					<view class="buy-num">{{ item.stock }}人付款</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	
	export default {
		name: 'goods-list',
		props: {
			goodsList: {
				type: Array,
				default () {
					return [];
				}
			}
		},
		methods: {
			toDetail(id) {
				uni.navigateTo({
					url: '/pages/goods/details?id=' + id
				})
			}
		}
	};
</script>

<style lang="scss" scoped>
	.goods-list {
		display: flex;
		flex-direction: column;
		/* 垂直布局 */
		align-items: center;
		/* 居中对齐 */
		background-color: #f5f5f5;
		padding: 5rpx;
		/* 整体的留白 */

		.goods-item {
			display: flex;
			width: 94%;
			/* 增加商品卡片的宽度 */
			margin: 12rpx 0;
			/* 上下间距 */
			border-radius: 12rpx;
			overflow: hidden;
			background-color: #FFF;
			height: 250rpx;
			/* 增加卡片整体高度 */
			box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
			/* 微弱阴影 */
			transition: all 0.15s ease-in-out;

			.goods-item-img {
				width: 200rpx;
				height: 220rpx;
				/* 增加图片高度 */
				overflow: hidden;
				border-top-left-radius: 12rpx;
				border-bottom-left-radius: 12rpx;

				image {
					width: 100%;
					height: 100%;
					object-fit: cover;
					/* 保持图片比例不变 */
				}
			}

			.goods-item-content {
				flex: 1;
				padding: 15rpx;
				/* 适度内边距 */
				display: flex;
				flex-direction: column;
				justify-content: space-between;

				.title {
					font-size: 15px;
					font-weight: 500;
					color: #2e2e2e;
					word-break: break-word;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					/* 限制两行显示 */
					margin-bottom: 8rpx;
				}

				.bottom {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.price {
						.sale-price {
							font-size: 18px;
							font-weight: 500;
							color: #e41f19;
						}

						.factory-price {
							font-size: 13px;
							color: #a0a0a0;
							text-decoration: line-through;
							padding-left: 4rpx;
						}
					}

					.buy-num {
						font-size: 13px;
						color: #656565;
					}
				}
			}
		}
	}
</style>